<template>
  <el-dialog
    :model-value="editDialogVisible"
    :destroy-on-close="true"
    title="编辑商户"
    width="680px"
    @close="emits('closeDialog')"
  >
    <el-form
      ref="dialogFormRef"
      :model="editDialogForm"
      :label-width="formLabelWidth"
      :rules="rules"
    >
      <el-form-item label="商户ID" prop="merchant_id">
        <el-input v-model="editDialogForm.merchant_id" readonly />
      </el-form-item>
      <el-form-item label="商户名称" prop="name">
        <el-input v-model="editDialogForm.name" />
      </el-form-item>
      <el-form-item label="昵称" prop="nickname">
        <el-input v-model="editDialogForm.nickname" />
      </el-form-item>
      <el-form-item label="主分类" prop="category">
        <el-input v-model="editDialogForm.category" />
      </el-form-item>
      <el-form-item label="子分类" prop="sub_category">
        <el-input v-model="editDialogForm.sub_category" />
      </el-form-item>
      <el-form-item label="是否KYC" prop="is_kyc">
        <el-select v-model="editDialogForm.is_kyc" placeholder="是否KYC">
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="法币钱包" prop="open_currency">
        <el-select
          v-model="editDialogForm.open_currency"
          placeholder="是否开通法币钱包"
        >
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="法币换汇" prop="open_currency_exchange">
        <el-select
          v-model="editDialogForm.open_currency_exchange"
          placeholder="是否开通法币换汇"
        >
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="法币充值" prop="open_currency_recharge">
        <el-select
          v-model="editDialogForm.open_currency_recharge"
          placeholder="是否开通法币充值"
        >
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="法币付款" prop="open_currency_payment">
        <el-select
          v-model="editDialogForm.open_currency_payment"
          placeholder="是否开通法币付款"
        >
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(editDialogForm)"
          :loading="btnLoading"
          >提交</el-button
        >
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";
const dialogFormRef = ref(null);

defineProps({
  editDialogVisible: {
    type: Boolean,
    default: false,
  },
  editDialogForm: {
    type: Object,
    default: {
      id: "",
      name: "",
      merchant_id: "",
      nickname: "",
      category: "",
      sub_category: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "150px";
// 校验
const rules = {
  name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  // merchant_id: [{ required: true, message: "请输入商户ID", trigger: "blur" }],
};
// 提交
const submit = (editDialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        const param = Object.assign({}, editDialogForm);
        emits("submitForm", param);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
</script>
